CalculatorController = function () {
	this._result = document.getElementById("result");
	this._num1 = document.getElementById("num1");
	this._num2 = document.getElementById("num2");
	this._operator = document.getElementById("op");
	this._calc = document.getElementById("calc");
	
	this._calculator = new Calculator();
	
	this._fnClickCalc = this._onClickCalc.bind(this);
	
	this._bindEvent();
};

CalculatorController.prototype = {
	_bindEvent: function () {
		this._addEventListener(this._calc, "click", this._fnClickCalc);
	},
	
	unbindEvent: function () {
		this._removeEventListener(this._calc, "click", this._fnClickCalc);
	},
	
	_isValidate: function (num1, num2) {
		var isValidate = true;
		
		return isValidate;
	},
	
	_onClickCalc: function (e) {
		var num1 = parseInt(this._getValue(this._num1), 10),
			num2 = parseInt(this._getValue(this._num2), 10),
			selectedIdx = this._operator.selectedIndex,
			op = this._operator[selectedIdx].text;
	
		if (this._isValidate(num1, num2)) {
			this._calculate(num1, num2, op);
		} else {
			// TODO 여기에 값이 유효하지 않을 때의 동작을 넣어주세요.
		}
	},
	
	_calculate: function (num1, num2, op) {
		var result = 0;
		
		switch (op) {
		case "+":
			result = this._calculator.add(num1, num2);
			break;
		case "-":
			result = this._calculator.subtract(num1, num2);
			break;
		case "*":
			result = this._calculator.multiply(num1, num2);
			break;
		case "/":
			result = this._calculator.divide(num1, num2);
			break;
		}
		
		this._result.value = result;
	},
	
	_getValue: function (elTxt) {
		return elTxt.value;
	},
	
	_addEventListener: function (el, eventType, handler) {
		if (el.addEventListener) {
			el.addEventListener (eventType, handler, false);
		} else if (el.attachEvent) {
			el.attachEvent ("on" + eventType, handler);
		}
	},
	
	_removeEventListener: function (el, eventType, handler) {
		if (el.removeEventListener) {
			el.removeEventListener(eventType, handler, false);
		} else if (el.detachEvent) {
			el.detachEvent("on" + eventType, handler);
		}
	}
};